/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import java.util.LinkedList;
import java.util.Random;

/**
 *
 * @author Stratos
 */
public class RandomGenerator {

    public Passenger generatePassenger(Metro metro) {
        String name = generateName();
        String surname = generateSurname();
        String type = generateType();
        Boolean wantsCard = generateBoolean();
        Passenger p = new Passenger(name, surname, type, wantsCard);
        Station nearestStation = generateNearestStation(metro.getRedLine());
        //System.out.println("Generated nearest Station: " + nearestStation);
        p.setNearestStation(nearestStation.getName());
        Station destination = generateDestination(nearestStation, metro.getRedLine());
        p.setGoTo(destination.getName());
        //System.out.println("++Generated destination: " + destination);

        return p;
    }

    public String generateName() {
        Random r1 = new Random();
        String returnName = "";
        String[] names = new String[]{
            "Tom", "Jacob", "Jake",
            "Ethan", "Jonathan", "Tyler", "Samuel", "Nicholas", "Angel",
            "Jayden", "Nathan", "Elijah", "Christian", "Gabriel", "Benjamin",
            "Emma", "Aiden", "Ryan", "James", "Abigail", "Logan", "John",
            "Daniel", "Alexander", "Isabella", "Anthony", "William", "Christopher", "Matthew", "Emily", "Madison",
            "Rob", "Ava", "Olivia", "Andrew", "Joseph", "David", "Sophia", "Noah",
            "Justin",};

        int indexF = r1.nextInt(names.length - 1);
        returnName = names[indexF];
        return returnName;
    }

    public String generateSurname() {
        Random r2 = new Random();
        String returnName = "";
        String[] lNames = new String[]{
            "Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore",
            "Taylor", "Anderson", "Thomas", "Jackson", "White", "Harris", "Martin", "Thompson", "Garcia",
            "Martinez", "Robinson", "Clark", "Lewis", "Lee", "Walker", "Hall", "Allen", "Young",
            "King", "Wright", "Hill", "Scott", "Green", "Adams", "Baker", "Carter", "Turner",};
        int indexL = r2.nextInt(lNames.length - 1);
        returnName = lNames[indexL];
        return returnName;
    }

    public String generateType() {
        String type = "";
        Random rand = new Random();
        Integer n = rand.nextInt(2) + 1;
        if (n == 1) {
            type = "Regular";
        } else if (n == 2) {
            type = "Student";
        } else if (n == 3) {
            type = "Soldier";
        }
        return type;
    }

    public Boolean generateBoolean() {
        Boolean b = false;
        Random rand = new Random();
        int n = rand.nextInt(2);
        if (n == 0) {
            b = false;
        } else if (n == 1) {
            b = true;
        }
        return b;
    }

    /*public Station findMyStation(String nearestStation, LinkedList<Station> list) {
        Station myStation = null;
        for (Station station : list) {
            if (station.getName().equalsIgnoreCase(nearestStation)) {
                myStation = station;
                System.out.println("found your station!");
            }
        }
        return myStation;
    }*/

    

    public Station generateNearestStation(LinkedList<Station> list) {
        int n = list.size();
        Random rand = new Random();
        int r = rand.nextInt(n);
        return list.get(r);
    }

    public Station generateDestination(Station startingStation, LinkedList<Station> list) {
        int i = list.indexOf(startingStation);
        int n = list.size();
        Random rand = new Random();
        int r;
        do {
            r = rand.nextInt(n);
        } while (r == i);
        
        return list.get(r);
    }

    
}
